home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / nktools.zip / DOS4TO5.ASM < prev    next >
Assembly Source File  |  1990-05-20  |  5KB  |  230 lines

  1. IDEAL
  2. MODEL    TPASCAL
  3.  
  4. DATASEG
  5.  
  6. ; The following record type describes the contents of the Program
  7. ; Segment Prefix (PSP).
  8. ;
  9. ;    int20H        exit code
  10. ;    TopOfMemory    Memory size in paragraphs
  11. ;    Reserved0        ??? (0)
  12. ;    PSP_DOS        Far call to DOS
  13. ;    TerminationAddr    Terminate address
  14. ;    BreakExitAddr    Address of break handler
  15. ;    CriticalErrorAddr    Address of critical error handler
  16. ;    ParentPSP_Seg    Parent PSP segment
  17. ;    OpenFiles        Open files, $ff = unused
  18. ;    EnvSeg    Environment segment
  19. ;    PSP_OldStack    far pointer to processes SS:SP ???
  20. ;    PSP_Nfiles        maximum open files
  21. ;    PSP_aofile        ofile address
  22. ;    Reserved3        Unused ???
  23. ;    PSP_int21        INT 21, far return
  24. ;    Reserved4        Unused ???
  25. ;    PSP_FCB1ext    FCB #1 extension
  26. ;    PSP_FCB1        FCB #1
  27. ;    PSP_FCB2ext    FCB #2 extension
  28. ;    PSP_FCB2        FCB #2
  29. ;    PSP_DMA        Command Tail
  30. ;
  31. STRUC    PSPtype
  32.     Int20        DW    ?        ;00
  33.     TopOfMemory    DW    ?        ;02
  34.     Reserved0    DB    ?        ;04
  35.     PSP_DOS        DB    5 DUP(?)    ;05
  36.     TerminationAddr    DD    ?        ;0A
  37.     BreakExitAddr    DD    ?        ;0E
  38.     CriticalErrAddr    DD    ?        ;12
  39.     ParentPSP_Seg    DW    ?        ;16
  40.     OpenFiles    DB    20 DUP(?)    ;18
  41.     EnvironmentSeg    DW    ?        ;2C
  42.     PSP_OldStack    DD    ?        ;2E
  43.     PSP_Nfiles    DW    ?        ;32
  44.     PSP_aofile    DD    ?        ;34
  45.     Reserved3    DB    24 DUP(?)    ;38
  46.     PSP_int21    DB    3 DUP(?)    ;50
  47.     Reserved4    DB    2 DUP(?)    ;53
  48.     PSP_FCB1ext    DB    7 DUP(?)    ;55
  49.     PSP_FCB1    DB    9 DUP(?)    ;5C
  50.     PSP_FCB2ext    DB    7 DUP(?)    ;65
  51.     PSP_FCB2    DB    20 DUP(?)    ;6C
  52.     PSP_DMA        DB    128 DUP(?)    ;80
  53. ENDS
  54.  
  55. EXTRN    PrefixSeg:WORD
  56.  
  57. CODESEG
  58.  
  59. PUBLIC    DosVersion
  60. PROC    DosVersion    FAR
  61.     mov    ah,30h
  62.     int    21h
  63.     ret
  64. ENDP
  65.  
  66. PUBLIC    GetCBreak
  67. PROC    GetCBreak    FAR
  68.     ARG    BreakPtr:DWORD
  69.     mov    ax,3300h
  70.     int    21h
  71.     or    al,al
  72.     jnz    @@Done        ; Error if AL=0xff
  73.     les    di,[BreakPtr]    ; DL=0/1    OFF/ON
  74.     mov    [es:di],dl
  75. @@Done:    ret
  76. ENDP
  77.  
  78. PUBLIC    SetCBreak
  79. PROC    SetCBreak    FAR
  80.     ARG    Break:BYTE
  81.     mov    ax,3301h
  82.     mov    dl,[Break]
  83.     or    dl,dl
  84.     jz    @@Go        ; Already zero, so go ahead
  85.     mov    dl,1        ; not zero, so make sure it's a 1
  86. @@Go:    int    21h
  87.     ret
  88. ENDP
  89.  
  90. PUBLIC    GetVerify
  91. PROC    GetVerify    FAR
  92.     ARG    VerifyPtr:DWORD
  93.     mov    ax,5400h
  94.     int    21h
  95.     les    di,[VerifyPtr]
  96.     mov    [es:di],al
  97.     ret
  98. ENDP
  99.  
  100. PUBLIC    SetVerify
  101. PROC    SetVerify    FAR
  102.     ARG    Verify:BYTE
  103.     mov    ax,2e00h
  104.     xor    dl,dl
  105.     test    [Verify],0ffh
  106.     jz    @@Go
  107.     inc    ax
  108. @@Go:    int    21h
  109.     ret
  110. ENDP
  111.  
  112. ; NAME:  GetEnv
  113. ;
  114. ; EXTERNALS:
  115. ;     word        PrefixSeg   (System)
  116. ;PROC    GetEnv    FAR
  117. ;    ARG    EnvVar:DWORD    RETURNS Result:DWORD
  118. ;    USES    ds
  119. ;    xor    cx,cx        ; clear CX
  120. ;    cld            ; forward string op
  121. ;    les    di,[EnvVar]
  122. ;    lodsb
  123. ;    mov    si,cx        ; clear SI
  124. ;    mov    cl,al        ; CX <- length of environ var
  125. ;    mov    ds,[PrefixSeg]
  126. ;    mov    ds,[ds:(PSPtype PTR si).EnvironmentSeg]
  127. ;@@More:    mov    al,[ds:si]
  128. ;    or    ax,ax
  129. ;    jz    @@Done
  130. ;@@Chk:    mov    al,[ds:si]
  131. ;    cmp    al,[]
  132. ;    mov
  133. ;@@Done:    ret
  134. ;ENDP
  135.  
  136. ;FUNCTION GetEnv( envvar : string ) : string;
  137. ;    VAR
  138. ;    i        : integer;
  139. ;    found        : boolean;
  140. ;    WorkBuffer    : string;
  141. ;    BEGIN  (* GetEnv *)
  142. ;    i := 0;
  143. ;    found := false;
  144. ;    WHILE NOT (found OR (mem[EnvironmentSeg:i]=0)) DO BEGIN
  145. ;        WorkBuffer := '';
  146. ;        WHILE mem[EnvironmentSeg:i] <> ord('=') DO BEGIN
  147. ;        WorkBuffer := WorkBuffer + chr(mem[EnvironmentSeg:i]);
  148. ;        Inc(i)
  149. ;          END;
  150. ;        Inc(i);        (* skip '=' *)
  151. ;        found := WorkBuffer = envvar;
  152. ;        WorkBuffer := '';
  153. ;        WHILE mem[EnvironmentSeg:i] <> 0 DO BEGIN
  154. ;        WorkBuffer := WorkBuffer + chr(mem[EnvironmentSeg:i]);
  155. ;        Inc(i)
  156. ;          END;
  157. ;        Inc(i)        (* skip '\0' *)
  158. ;      END;
  159. ;    IF found THEN
  160. ;        GetEnv := WorkBuffer
  161. ;    ELSE
  162. ;        GetEnv := ''
  163. ;    END;  (* GetEnv *)
  164.  
  165. ;-----------------------------------------------------------------------
  166. ; NAME:  EnvCount
  167. ;
  168. ; EXTERNALS:
  169. ;     word        PrefixSeg   (System)
  170. ; REGISTER USAGE:   AX,BX,DI,ES        -- Destroyed
  171. ;-----------------------------------------------------------------------
  172. PUBLIC    EnvCount
  173. PROC    EnvCount    FAR
  174.     cld            ; forward string op
  175.     xor    ax,ax        ; clear AX
  176.     mov    bx,ax        ; clear BX
  177.     mov    di,ax        ; clear DI
  178.     mov    es,[PrefixSeg]
  179.     mov    es,[es:(PSPtype PTR di).EnvironmentSeg]
  180. @@EnvEndChk:
  181.     scasb            ; is es:di=0 ?
  182.     jz    @@Done
  183.     inc    bx
  184. @@More:    scasb            ; look for end of environment
  185.     jnz    @@More        ;    string.
  186.     jmp    @@EnvEndChk
  187. @@Done:    mov    ax,bx
  188.     ret
  189. ENDP
  190.  
  191. ;-----------------------------------------------------------------------
  192. ; NAME:  EnvStr
  193. ;
  194. ; EXTERNALS:
  195. ;     word        PrefixSeg   (System)
  196. ; REGISTER USAGE:   AX,CX,DI,ES        -- Destroyed
  197. ;-----------------------------------------------------------------------
  198. PUBLIC    EnvStr
  199. PROC    EnvStr    FAR
  200.     ARG    Index:Word    RETURNS    Result:DWORD
  201.     USES    ds
  202.     cld            ; forward string op
  203.     xor    ax,ax        ; clear AX
  204.     mov    si,ax        ; clear SI
  205.     les    di,[Result]
  206.     stosb            ; set result length to 0
  207.     mov    cx,[Index]    ; get index
  208.     jcxz    @@Done
  209.     mov    ds,[PrefixSeg]
  210.     mov    ds,[ds:(PSPtype PTR si).EnvironmentSeg]
  211. @@EnvEndChk:
  212.     test    [BYTE PTR si],0ffh
  213.     jz    @@Done
  214.     dec    cx
  215.     jcxz    @@Found
  216. @@More:    lodsb            ; look for end of environment
  217.     or    ax,ax        ; string
  218.     jnz    @@More        ;
  219.     jmp    @@EnvEndChk
  220. @@Found:movsb
  221.     inc    cx
  222.     test    [BYTE PTR si],0ffh
  223.     jnz    @@Found
  224.     les    di,[Result]
  225.     mov    [es:di],cl    ; set length
  226. @@Done:    ret
  227. ENDP
  228.  
  229. END
  230.